<?php

class Core_Backend_Component_Article_View_Content_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('article/content/index'), $this->__('share.button.back'));
        if($this->getIdentity()->isAllowAction('article_edit')){
	        $group = $toolbar->createGroup('save');
	        $group->addButton($this->__('share.button.submit'))
	        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(array('status'=>'pending'), 'save')."')");
	        $group->addButton($this->__('share.button.save'))
	        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        }
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('content_form')
                ->addHiddenField('id', 'content[id]');
        $form->addTextboxField($this->__('share.label.title'), 'title', 'content[title]', TRUE)
                ->addValidateRule('required');
        $form->addComboTreeField($this->__('article.label.category'), 'category_id', "content[category_id]", TRUE)
                ->bindData($this->getCategories()->toArray(), 0, array('valueKey'=>'id', 'textKey'=>'title', 'parentKey'=>'parent_id', 'childKey'=>'id'));
        $form->addTextboxField($this->__('share.label.sef_url'), 'sef_url', 'content[sef_url]');
        $form->addTextboxField($this->__('article.label.author'), 'author', 'content[author]');
        $form->addDatetimeField($this->__('share.label.start_time'), 'start_time', 'content[start_time]')
                ->setFormat('Y-m-d')
                ->setCurrentDate();
        $form->addDatetimeField($this->__('share.label.end_time'), 'end_time', 'content[end_time]')
                ->setFormat('Y-m-t');
      	$form->addTextboxField($this->__('article.label.resource'), 'resource', 'content[resource]');
        $form->addTextboxField($this->__('article.label.clickcount'),'click_count','content[click_count]');
        $form->addTextboxField($this->__('share.label.tag'), 'tag', 'content[tag]');
        $form->addBooleanField($this->__('article.label.hot'), 'is_hot', 'content[is_hot]')
                ->setYesOption($this->__('status.boolean.1'))
                ->setNoOption($this->__('status.boolean.0'));
        $form->addBooleanField($this->__('article.label.new'), 'is_new', 'content[is_new]')
                ->setYesOption($this->__('status.boolean.1'))
                ->setNoOption($this->__('status.boolean.0'));
        $form->addBooleanField($this->__('article.label.top'), 'is_top', 'content[is_top]')
                ->setYesOption($this->__('status.boolean.1'))
                ->setNoOption($this->__('status.boolean.0'));
        $form->addFileBrowserField($this->__('subject.label.picture'), 'picture', 'content[picture]')
                ->setPath('pub/media/article')
                ->setFileType('image')
                ->setCallback('selectArticlePictute');
        $form->addTextareaField($this->__('share.label.introduction'), 'introduction', 'content[introduction]');
        $form->addEditorField($this->__('article.label.content'), 'content', 'content[content]');
        $form->createTab('base_option', $this->__('article.label.base_option'),
                array('field_title', 'field_category_id', 'field_sef_url', 'field_author', 'field_resource', 'field_tag', 'field_introduction','field_click_count'));
        $form->createTab('content_option', $this->__('article.label.content'), array('field_content'));
        $form->createTab('picture_option', $this->__('article.label.picture_option'), array('field_picture'));
        $form->createTab('display_option', $this->__('article.label.display_option'),
                array('field_start_time', 'field_end_time', 'field_is_hot', 'field_is_new', 'field_is_top'));
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}